<style>
    .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
</style>
<div class="layuimini-container layui-anim layui-anim-upbit">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="old_password" lay-reqtext="旧的密码不能为空" placeholder="请输入旧的密码"  value="" class="layui-input">
                    <tip>填写自己账号的旧的密码。</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="new_password" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="again_password" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>

<script>
    layui.use(['form','layuimini'], function () {
        var form = layui.form,
            layer = layui.layer,
            layuimini = layui.layuimini;
        form.render();
        //监听提交
        form.on('submit(saveBtn)', function (data) {
        	console.log(data.field);
        	if(data.field.old_password==null||data.field.old_password==""){
        		layer.alert("旧的密码不能为空");
        		return;
        	}
        	if(data.field.new_password==null||data.field.new_password==""){
        		layer.alert("新的密码不能为空");
        		return;
        	}
        	if(data.field.again_password==null||data.field.again_password==""
        			|| data.field.again_password !=data.field.new_password){
        		layer.alert("新的密码不一致");
        		return;
        	}
        	$.post("/private/user/updatePassword",data.field,function(obj){
        		layer.alert(obj.message);
        		if(obj.success){
        			$.cookie("token","", {path: '/'});
           	   	 	$.cookie("username","", {path: '/'});
           	   	 	$.cookie("type","", {path: '/'});
                    window.location = 'login';
        		}
        	},"json");
        });
    });
</script>